import type { LucideIcon } from "lucide-react"
import {
  Zap,
  MessageSquare,
  Database,
  Code,
  GitBranch,
  Filter,
  FileText,
  Globe,
  Mail,
  Clock,
  Search,
  Calculator,
  Brain,
  DatabaseIcon,
  Image,
  Music,
  FileQuestion,
  Webhook,
  Terminal,
  FileSpreadsheet,
  Merge,
  Split,
  Repeat,
  AlertCircle,
  CheckCircle,
  Bot,
  Settings,
  Key,
  Book,
  Type,
} from "lucide-react"

// 参数类型定义
export type ParameterType =
  | "string"
  | "number"
  | "boolean"
  | "object"
  | "array"
  | "file"
  | "image"
  | "json"
  | "text"
  | "email"
  | "url"
  | "datetime"
  | "select"
  | "multiselect"
  | "any"

// 参数定义
export interface NodeParameter {
  name: string
  label: string
  type: ParameterType
  required?: boolean
  defaultValue?: any
  description?: string
  options?: Array<{ label: string; value: any }> // for select/multiselect
  placeholder?: string
  validation?: {
    min?: number
    max?: number
    pattern?: string
    message?: string
  }
}

// 节点配置接口
export interface NodeConfig {
  id: string
  type: string
  label: string
  iconName: string
  category: string
  description: string
  inputs: NodeParameter[]
  outputs: NodeParameter[]
  config?: {
    color?: string
    allowMultipleInputs?: boolean
    allowMultipleOutputs?: boolean
    maxInputs?: number
    maxOutputs?: number
  }
}

// 图标映射
export const iconMap: Record<string, LucideIcon> = {
  Zap,
  MessageSquare,
  Database,
  Code,
  GitBranch,
  Filter,
  FileText,
  Globe,
  Mail,
  Clock,
  Search,
  Calculator,
  Brain,
  DatabaseIcon,
  Image,
  Music,
  FileQuestion,
  Webhook,
  Terminal,
  FileSpreadsheet,
  Merge,
  Split,
  Repeat,
  AlertCircle,
  CheckCircle,
  Bot,
  Settings,
  Key,
  Book,
  Type,
}

// Dify 工作流节点配置
export const difyNodeConfigs: NodeConfig[] = [
  // 基础节点
  {
    id: "trigger",
    type: "trigger",
    label: "触发器",
    iconName: "Zap",
    category: "基础",
    description: "工作流的起始节点，定义触发条件",
    inputs: [],
    outputs: [
      {
        name: "event",
        label: "事件数据",
        type: "object",
        description: "触发事件携带的数据",
      },
      {
        name: "timestamp",
        label: "触发时间",
        type: "datetime",
        description: "事件触发的时间戳",
      },
    ],
    config: {
      color: "blue",
      allowMultipleOutputs: true,
    },
  },
  {
    id: "end",
    type: "end",
    label: "结束",
    iconName: "CheckCircle",
    category: "基础",
    description: "工作流的结束节点",
    inputs: [
      {
        name: "result",
        label: "最终结果",
        type: "any",
        description: "工作流执行的最终结果",
      },
      {
        name: "status",
        label: "状态",
        type: "string",
        description: "执行状态（成功/失败）",
      },
    ],
    outputs: [],
    config: {
      color: "green",
    },
  },

  // AI 节点
  {
    id: "llm",
    type: "llm",
    label: "LLM",
    iconName: "MessageSquare",
    category: "AI",
    description: "调用大语言模型进行文本处理",
    inputs: [
      {
        name: "prompt",
        label: "提示词",
        type: "text",
        required: true,
        description: "发送给模型的提示词",
        placeholder: "请输入提示词...",
      },
      {
        name: "context",
        label: "上下文",
        type: "text",
        description: "额外的上下文信息",
      },
      {
        name: "temperature",
        label: "温度",
        type: "number",
        defaultValue: 0.7,
        description: "控制输出的随机性（0-2）",
        validation: { min: 0, max: 2 },
      },
    ],
    outputs: [
      {
        name: "response",
        label: "模型回复",
        type: "text",
        description: "LLM 生成的文本",
      },
      {
        name: "tokens",
        label: "Token 数",
        type: "number",
        description: "消耗的 token 数量",
      },
    ],
  },
  {
    id: "knowledge",
    type: "knowledge",
    label: "知识库",
    iconName: "Database",
    category: "AI",
    description: "从知识库检索相关信息",
    inputs: [
      {
        name: "query",
        label: "查询",
        type: "string",
        required: true,
        description: "检索查询文本",
      },
      {
        name: "topK",
        label: "返回数量",
        type: "number",
        defaultValue: 5,
        description: "返回最相关的 K 个结果",
      },
      {
        name: "threshold",
        label: "相似度阈值",
        type: "number",
        defaultValue: 0.7,
        description: "最低相似度要求",
        validation: { min: 0, max: 1 },
      },
    ],
    outputs: [
      {
        name: "documents",
        label: "检索文档",
        type: "array",
        description: "检索到的相关文档",
      },
      {
        name: "scores",
        label: "相似度分数",
        type: "array",
        description: "每个文档的相似度分数",
      },
    ],
  },
  {
    id: "image-generation",
    type: "image-generation",
    label: "图像生成",
    iconName: "Image",
    category: "AI",
    description: "使用 AI 生成图像",
    inputs: [
      {
        name: "prompt",
        label: "图像描述",
        type: "text",
        required: true,
        description: "描述要生成的图像",
      },
      {
        name: "size",
        label: "尺寸",
        type: "select",
        defaultValue: "1024x1024",
        options: [
          { label: "256x256", value: "256x256" },
          { label: "512x512", value: "512x512" },
          { label: "1024x1024", value: "1024x1024" },
        ],
      },
    ],
    outputs: [
      {
        name: "imageUrl",
        label: "图像URL",
        type: "url",
        description: "生成图像的 URL",
      },
    ],
  },

  // 逻辑节点
  {
    id: "condition",
    type: "condition",
    label: "条件判断",
    iconName: "GitBranch",
    category: "逻辑",
    description: "根据条件分支执行不同路径",
    inputs: [
      {
        name: "value",
        label: "判断值",
        type: "any",
        required: true,
        description: "要判断的值",
      },
      {
        name: "operator",
        label: "运算符",
        type: "select",
        options: [
          { label: "等于", value: "==" },
          { label: "不等于", value: "!=" },
          { label: "大于", value: ">" },
          { label: "小于", value: "<" },
          { label: "包含", value: "contains" },
          { label: "为空", value: "isEmpty" },
        ],
      },
      {
        name: "compareValue",
        label: "比较值",
        type: "any",
        description: "用于比较的值",
      },
    ],
    outputs: [
      {
        name: "true",
        label: "条件为真",
        type: "any",
        description: "条件满足时的输出",
      },
      {
        name: "false",
        label: "条件为假",
        type: "any",
        description: "条件不满足时的输出",
      },
    ],
  },
  {
    id: "code",
    type: "code",
    label: "代码执行",
    iconName: "Code",
    category: "逻辑",
    description: "执行自定义代码逻辑",
    inputs: [
      {
        name: "input",
        label: "输入数据",
        type: "any",
        description: "传入代码的数据",
      },
      {
        name: "code",
        label: "代码",
        type: "text",
        required: true,
        description: "要执行的代码",
        placeholder: "function run(input) {\n  // 你的代码\n  return result;\n}",
      },
    ],
    outputs: [
      {
        name: "result",
        label: "执行结果",
        type: "any",
        description: "代码执行的返回值",
      },
      {
        name: "error",
        label: "错误信息",
        type: "string",
        description: "执行出错时的错误信息",
      },
    ],
  },
  {
    id: "loop",
    type: "loop",
    label: "循环",
    iconName: "Repeat",
    category: "逻辑",
    description: "对数组元素进行循环处理",
    inputs: [
      {
        name: "items",
        label: "循环数组",
        type: "array",
        required: true,
        description: "要循环的数组",
      },
      {
        name: "maxIterations",
        label: "最大次数",
        type: "number",
        defaultValue: 100,
        description: "最大循环次数限制",
      },
    ],
    outputs: [
      {
        name: "item",
        label: "当前元素",
        type: "any",
        description: "当前循环的元素",
      },
      {
        name: "index",
        label: "索引",
        type: "number",
        description: "当前元素的索引",
      },
      {
        name: "results",
        label: "结果数组",
        type: "array",
        description: "所有循环结果的数组",
      },
    ],
  },
  {
    id: "merge",
    type: "merge",
    label: "合并",
    iconName: "Merge",
    category: "逻辑",
    description: "合并多个输入",
    inputs: [
      {
        name: "input1",
        label: "输入1",
        type: "any",
        description: "第一个输入",
      },
      {
        name: "input2",
        label: "输入2",
        type: "any",
        description: "第二个输入",
      },
      {
        name: "input3",
        label: "输入3",
        type: "any",
        description: "第三个输入",
      },
    ],
    outputs: [
      {
        name: "merged",
        label: "合并结果",
        type: "any",
        description: "合并后的数据",
      },
    ],
    config: {
      allowMultipleInputs: true,
      maxInputs: 10,
    },
  },

  // 数据处理节点
  {
    id: "template",
    type: "template",
    label: "模板",
    iconName: "FileText",
    category: "数据",
    description: "使用模板生成文本",
    inputs: [
      {
        name: "template",
        label: "模板",
        type: "text",
        required: true,
        description: "文本模板，使用 {{variable}} 引用变量",
        placeholder: "Hello {{name}}!",
      },
      {
        name: "variables",
        label: "变量",
        type: "object",
        description: "模板中使用的变量",
      },
    ],
    outputs: [
      {
        name: "text",
        label: "生成文本",
        type: "string",
        description: "根据模板生成的文本",
      },
    ],
  },
  {
    id: "variable",
    type: "variable",
    label: "变量",
    iconName: "Filter",
    category: "数据",
    description: "定义和存储变量",
    inputs: [
      {
        name: "name",
        label: "变量名",
        type: "string",
        required: true,
        description: "变量的名称",
      },
      {
        name: "value",
        label: "变量值",
        type: "any",
        description: "变量的值",
      },
    ],
    outputs: [
      {
        name: "value",
        label: "变量值",
        type: "any",
        description: "存储的变量值",
      },
    ],
  },
  {
    id: "json-parse",
    type: "json-parse",
    label: "JSON 解析",
    iconName: "FileSpreadsheet",
    category: "数据",
    description: "解析 JSON 字符串",
    inputs: [
      {
        name: "jsonString",
        label: "JSON字符串",
        type: "string",
        required: true,
        description: "要解析的 JSON 字符串",
      },
    ],
    outputs: [
      {
        name: "data",
        label: "解析结果",
        type: "object",
        description: "解析后的对象",
      },
      {
        name: "error",
        label: "错误",
        type: "string",
        description: "解析失败的错误信息",
      },
    ],
  },
  {
    id: "data-transform",
    type: "data-transform",
    label: "数据转换",
    iconName: "Settings",
    category: "数据",
    description: "转换数据格式",
    inputs: [
      {
        name: "data",
        label: "输入数据",
        type: "any",
        required: true,
        description: "要转换的数据",
      },
      {
        name: "mapping",
        label: "映射规则",
        type: "object",
        description: "字段映射规则",
      },
    ],
    outputs: [
      {
        name: "transformed",
        label: "转换结果",
        type: "any",
        description: "转换后的数据",
      },
    ],
  },

  // 集成节点
  {
    id: "http",
    type: "http",
    label: "HTTP 请求",
    iconName: "Globe",
    category: "集成",
    description: "发送 HTTP 请求",
    inputs: [
      {
        name: "url",
        label: "URL",
        type: "url",
        required: true,
        description: "请求的 URL",
        placeholder: "https://api.example.com/data",
      },
      {
        name: "method",
        label: "请求方法",
        type: "select",
        defaultValue: "GET",
        options: [
          { label: "GET", value: "GET" },
          { label: "POST", value: "POST" },
          { label: "PUT", value: "PUT" },
          { label: "DELETE", value: "DELETE" },
          { label: "PATCH", value: "PATCH" },
        ],
      },
      {
        name: "headers",
        label: "请求头",
        type: "object",
        description: "HTTP 请求头",
      },
      {
        name: "body",
        label: "请求体",
        type: "any",
        description: "请求体数据",
      },
    ],
    outputs: [
      {
        name: "response",
        label: "响应数据",
        type: "any",
        description: "HTTP 响应的数据",
      },
      {
        name: "status",
        label: "状态码",
        type: "number",
        description: "HTTP 状态码",
      },
      {
        name: "headers",
        label: "响应头",
        type: "object",
        description: "响应的 HTTP 头",
      },
    ],
  },
  {
    id: "webhook",
    type: "webhook",
    label: "Webhook",
    iconName: "Webhook",
    category: "集成",
    description: "接收 Webhook 调用",
    inputs: [],
    outputs: [
      {
        name: "payload",
        label: "请求数据",
        type: "object",
        description: "Webhook 接收到的数据",
      },
      {
        name: "headers",
        label: "请求头",
        type: "object",
        description: "请求的 HTTP 头",
      },
    ],
  },
  {
    id: "email",
    type: "email",
    label: "邮件发送",
    iconName: "Mail",
    category: "集成",
    description: "发送电子邮件",
    inputs: [
      {
        name: "to",
        label: "收件人",
        type: "email",
        required: true,
        description: "收件人邮箱地址",
      },
      {
        name: "subject",
        label: "主题",
        type: "string",
        required: true,
        description: "邮件主题",
      },
      {
        name: "body",
        label: "邮件内容",
        type: "text",
        required: true,
        description: "邮件正文",
      },
      {
        name: "cc",
        label: "抄送",
        type: "string",
        description: "抄送邮箱地址",
      },
    ],
    outputs: [
      {
        name: "success",
        label: "发送成功",
        type: "boolean",
        description: "是否发送成功",
      },
      {
        name: "messageId",
        label: "消息ID",
        type: "string",
        description: "邮件的唯一标识",
      },
    ],
  },
  {
    id: "database",
    type: "database",
    label: "数据库查询",
    iconName: "DatabaseIcon",
    category: "集成",
    description: "执行数据库查询",
    inputs: [
      {
        name: "query",
        label: "SQL查询",
        type: "text",
        required: true,
        description: "SQL 查询语句",
        placeholder: "SELECT * FROM users WHERE id = ?",
      },
      {
        name: "parameters",
        label: "参数",
        type: "array",
        description: "查询参数",
      },
    ],
    outputs: [
      {
        name: "rows",
        label: "查询结果",
        type: "array",
        description: "查询返回的行数据",
      },
      {
        name: "rowCount",
        label: "行数",
        type: "number",
        description: "返回的行数",
      },
    ],
  },

  // 工具节点
  {
    id: "delay",
    type: "delay",
    label: "延迟",
    iconName: "Clock",
    category: "工具",
    description: "延迟执行指定时间",
    inputs: [
      {
        name: "duration",
        label: "延迟时长",
        type: "number",
        required: true,
        description: "延迟的毫秒数",
        defaultValue: 1000,
      },
      {
        name: "data",
        label: "透传数据",
        type: "any",
        description: "延迟后传递的数据",
      },
    ],
    outputs: [
      {
        name: "data",
        label: "输出数据",
        type: "any",
        description: "延迟后输出的数据",
      },
    ],
  },
  {
    id: "error-handler",
    type: "error-handler",
    label: "错误处理",
    iconName: "AlertCircle",
    category: "工具",
    description: "捕获和处理错误",
    inputs: [
      {
        name: "error",
        label: "错误",
        type: "any",
        description: "捕获到的错误",
      },
      {
        name: "fallbackValue",
        label: "默认值",
        type: "any",
        description: "出错时的默认返回值",
      },
    ],
    outputs: [
      {
        name: "handled",
        label: "处理结果",
        type: "any",
        description: "错误处理后的结果",
      },
      {
        name: "errorMessage",
        label: "错误信息",
        type: "string",
        description: "错误的详细信息",
      },
    ],
  },
]

// Coze 工作流节点配置（类似但有些不同）
export const cozeNodeConfigs: NodeConfig[] = [
  {
    id: "start",
    type: "start",
    label: "开始",
    iconName: "Zap",
    category: "基础",
    description: "工作流的起始节点",
    inputs: [],
    outputs: [
      {
        name: "input",
        label: "输入数据",
        type: "object",
        description: "工作流的输入参数",
      },
    ],
  },
  {
    id: "end",
    type: "end",
    label: "结束",
    iconName: "CheckCircle",
    category: "基础",
    description: "工作流的结束节点",
    inputs: [
      {
        name: "output",
        label: "输出数据",
        type: "any",
        description: "工作流的输出结果",
      },
    ],
    outputs: [],
  },
  {
    id: "llm",
    type: "llm",
    label: "大模型",
    iconName: "MessageSquare",
    category: "AI",
    description: "调用大语言模型",
    inputs: [
      {
        name: "prompt",
        label: "提示词",
        type: "text",
        required: true,
        description: "发送给模型的提示词",
      },
      {
        name: "model",
        label: "模型",
        type: "select",
        options: [
          { label: "GPT-4", value: "gpt-4" },
          { label: "GPT-3.5", value: "gpt-3.5-turbo" },
          { label: "Claude", value: "claude-2" },
        ],
      },
    ],
    outputs: [
      {
        name: "response",
        label: "模型回复",
        type: "text",
      },
    ],
  },
  // ... 其他节点类似 dify，这里简化
  ...difyNodeConfigs.filter((n) => ["code", "condition", "variable", "http"].includes(n.type)),
]

// Agent 组件节点配置
export const agentComponentConfigs: NodeConfig[] = [
  {
    id: "llm",
    type: "llm",
    label: "语言模型",
    iconName: "Brain",
    category: "核心",
    description: "Agent 的核心语言模型",
    inputs: [
      {
        name: "provider",
        label: "模型提供商",
        type: "select",
        required: true,
        defaultValue: "openai",
        options: [
          { label: "OpenAI", value: "openai" },
          { label: "Anthropic Claude", value: "anthropic" },
          { label: "Google Gemini", value: "google" },
          { label: "Azure OpenAI", value: "azure" },
          { label: "阿里通义千问", value: "qwen" },
          { label: "智谱 ChatGLM", value: "glm" },
          { label: "百度文心一言", value: "ernie" },
        ],
        description: "选择模型提供商",
      },
      {
        name: "model",
        label: "模型名称",
        type: "select",
        required: true,
        defaultValue: "gpt-4",
        options: [
          { label: "GPT-4 Turbo", value: "gpt-4-turbo" },
          { label: "GPT-4", value: "gpt-4" },
          { label: "GPT-3.5 Turbo", value: "gpt-3.5-turbo" },
          { label: "Claude 3.5 Sonnet", value: "claude-3-5-sonnet" },
          { label: "Claude 3 Opus", value: "claude-3-opus" },
          { label: "Gemini 1.5 Pro", value: "gemini-1.5-pro" },
          { label: "Gemini 1.5 Flash", value: "gemini-1.5-flash" },
          { label: "Qwen-Max", value: "qwen-max" },
          { label: "GLM-4", value: "glm-4" },
        ],
        description: "选择具体模型",
      },
      {
        name: "systemPrompt",
        label: "系统提示词",
        type: "text",
        required: true,
        description: "定义 Agent 的角色和行为",
        placeholder: "你是一个专业的AI助手，擅长...",
      },
      {
        name: "userMessage",
        label: "用户消息",
        type: "text",
        description: "用户的输入消息",
        placeholder: "请输入用户消息模板",
      },
      {
        name: "temperature",
        label: "温度",
        type: "number",
        defaultValue: 0.7,
        validation: { min: 0, max: 2 },
        description: "控制输出的随机性，0-2之间",
      },
      {
        name: "maxTokens",
        label: "最大Token数",
        type: "number",
        defaultValue: 2000,
        validation: { min: 1, max: 128000 },
        description: "限制输出的最大长度",
      },
      {
        name: "topP",
        label: "Top P",
        type: "number",
        defaultValue: 1.0,
        validation: { min: 0, max: 1 },
        description: "核采样参数",
      },
    ],
    outputs: [
      {
        name: "response",
        label: "模型响应",
        type: "text",
        description: "模型生成的完整响应",
      },
      {
        name: "reasoning",
        label: "推理过程",
        type: "text",
        description: "模型的思考过程（如支持）",
      },
      {
        name: "tokensUsed",
        label: "Token使用量",
        type: "number",
        description: "本次调用消耗的token数",
      },
    ],
  },
  {
    id: "memory",
    type: "memory",
    label: "记忆系统",
    iconName: "DatabaseIcon",
    category: "核心",
    description: "存储和检索对话历史",
    inputs: [
      {
        name: "storageType",
        label: "存储类型",
        type: "select",
        defaultValue: "shortTerm",
        options: [
          { label: "短期记忆", value: "shortTerm" },
          { label: "长期记忆", value: "longTerm" },
          { label: "向量记忆", value: "vector" },
        ],
        description: "选择记忆存储类型",
      },
      {
        name: "message",
        label: "消息",
        type: "object",
        description: "要存储的消息",
      },
      {
        name: "query",
        label: "检索查询",
        type: "string",
        description: "检索相关记忆的查询",
        placeholder: "搜索相关对话...",
      },
      {
        name: "maxHistory",
        label: "最大历史数",
        type: "number",
        defaultValue: 10,
        validation: { min: 1, max: 100 },
        description: "保留的最大历史记录数",
      },
      {
        name: "similarityThreshold",
        label: "相似度阈值",
        type: "number",
        defaultValue: 0.7,
        validation: { min: 0, max: 1 },
        description: "向量检索的相似度阈值",
      },
    ],
    outputs: [
      {
        name: "history",
        label: "对话历史",
        type: "array",
        description: "历史对话记录",
      },
      {
        name: "relevantMemories",
        label: "相关记忆",
        type: "array",
        description: "检索到的相关记忆",
      },
      {
        name: "memoryCount",
        label: "记忆数量",
        type: "number",
        description: "当前存储的记忆总数",
      },
    ],
  },
  {
    id: "planner",
    type: "planner",
    label: "任务规划器",
    iconName: "MessageSquare",
    category: "核心",
    description: "规划任务执行步骤",
    inputs: [
      {
        name: "goal",
        label: "目标",
        type: "string",
        required: true,
        description: "要完成的目标",
      },
      {
        name: "availableTools",
        label: "可用工具",
        type: "array",
        description: "可以使用的工具列表",
      },
    ],
    outputs: [
      {
        name: "plan",
        label: "执行计划",
        type: "array",
        description: "规划的执行步骤",
      },
      {
        name: "nextStep",
        label: "下一步",
        type: "object",
        description: "当前要执行的步骤",
      },
    ],
  },
  {
    id: "search-tool",
    type: "tool",
    label: "搜索工具",
    iconName: "Search",
    category: "工具",
    description: "在线搜索信息",
    inputs: [
      {
        name: "query",
        label: "搜索查询",
        type: "string",
        required: true,
        description: "搜索关键词",
      },
      {
        name: "maxResults",
        label: "最大结果数",
        type: "number",
        defaultValue: 5,
      },
    ],
    outputs: [
      {
        name: "results",
        label: "搜索结果",
        type: "array",
        description: "搜索返回的结果列表",
      },
    ],
  },
  {
    id: "calculator-tool",
    type: "tool",
    label: "计算器",
    iconName: "Calculator",
    category: "工具",
    description: "执行数学计算",
    inputs: [
      {
        name: "expression",
        label: "表达式",
        type: "string",
        required: true,
        description: "数学表达式",
        placeholder: "2 + 2 * 3",
      },
    ],
    outputs: [
      {
        name: "result",
        label: "计算结果",
        type: "number",
        description: "计算的结果",
      },
    ],
  },
  {
    id: "document-tool",
    type: "tool",
    label: "文档处理",
    iconName: "FileText",
    category: "工具",
    description: "读取和处理文档",
    inputs: [
      {
        name: "filePath",
        label: "文件路径",
        type: "string",
        required: true,
        description: "文档文件路径",
      },
      {
        name: "action",
        label: "操作",
        type: "select",
        options: [
          { label: "读取", value: "read" },
          { label: "提取", value: "extract" },
          { label: "摘要", value: "summarize" },
        ],
      },
    ],
    outputs: [
      {
        name: "content",
        label: "文档内容",
        type: "text",
        description: "处理后的文档内容",
      },
      {
        name: "metadata",
        label: "元数据",
        type: "object",
        description: "文档的元数据",
      },
    ],
  },
  {
    id: "api-tool",
    type: "tool",
    label: "API 调用",
    iconName: "Globe",
    category: "工具",
    description: "调用外部 API",
    inputs: [
      {
        name: "url",
        label: "API地址",
        type: "url",
        required: true,
      },
      {
        name: "method",
        label: "请求方法",
        type: "select",
        defaultValue: "GET",
        options: [
          { label: "GET", value: "GET" },
          { label: "POST", value: "POST" },
        ],
      },
      {
        name: "params",
        label: "参数",
        type: "object",
      },
    ],
    outputs: [
      {
        name: "response",
        label: "响应",
        type: "any",
      },
    ],
  },
  {
    id: "code-tool",
    type: "tool",
    label: "代码执行",
    iconName: "Code",
    category: "工具",
    description: "执行代码片段",
    inputs: [
      {
        name: "code",
        label: "代码",
        type: "text",
        required: true,
        description: "要执行的代码",
        placeholder: "print('Hello World')",
      },
      {
        name: "language",
        label: "语言",
        type: "select",
        defaultValue: "python",
        options: [
          { label: "Python", value: "python" },
          { label: "JavaScript", value: "javascript" },
          { label: "Shell", value: "shell" },
          { label: "TypeScript", value: "typescript" },
        ],
        description: "选择代码执行语言",
      },
      {
        name: "timeout",
        label: "超时时间(秒)",
        type: "number",
        defaultValue: 30,
        validation: { min: 1, max: 300 },
        description: "代码执行超时时间",
      },
    ],
    outputs: [
      {
        name: "output",
        label: "执行输出",
        type: "text",
        description: "标准输出内容",
      },
      {
        name: "error",
        label: "错误",
        type: "string",
        description: "错误输出内容",
      },
      {
        name: "exitCode",
        label: "退出码",
        type: "number",
        description: "程序退出码",
      },
    ],
  },
  {
    id: "knowledge-base",
    type: "knowledge",
    label: "知识库",
    iconName: "Book",
    category: "核心",
    description: "查询知识库获取相关信息",
    inputs: [
      {
        name: "query",
        label: "查询内容",
        type: "string",
        required: true,
        description: "查询的问题或关键词",
        placeholder: "请输入查询内容...",
      },
      {
        name: "knowledgeBaseId",
        label: "知识库ID",
        type: "string",
        description: "指定知识库的ID",
      },
      {
        name: "topK",
        label: "返回结果数",
        type: "number",
        defaultValue: 5,
        validation: { min: 1, max: 20 },
        description: "返回最相关的K个结果",
      },
      {
        name: "scoreThreshold",
        label: "相关性阈值",
        type: "number",
        defaultValue: 0.7,
        validation: { min: 0, max: 1 },
        description: "相关性分数阈值",
      },
    ],
    outputs: [
      {
        name: "documents",
        label: "相关文档",
        type: "array",
        description: "检索到的相关文档",
      },
      {
        name: "sources",
        label: "来源",
        type: "array",
        description: "文档来源信息",
      },
    ],
  },
  {
    id: "prompt-template",
    type: "prompt",
    label: "提示词模板",
    iconName: "FileText",
    category: "核心",
    description: "使用提示词模板生成提示",
    inputs: [
      {
        name: "template",
        label: "模板内容",
        type: "text",
        required: true,
        description: "提示词模板，支持 {{变量}} 语法",
        placeholder: "你好{{name}}，请帮我{{task}}",
      },
      {
        name: "variables",
        label: "变量值",
        type: "object",
        description: "模板中变量的值",
      },
    ],
    outputs: [
      {
        name: "prompt",
        label: "生成的提示词",
        type: "text",
        description: "填充变量后的完整提示词",
      },
    ],
  },
  {
    id: "web-scraper",
    type: "tool",
    label: "网页抓取",
    iconName: "Globe",
    category: "工具",
    description: "抓取网页内容",
    inputs: [
      {
        name: "url",
        label: "网页URL",
        type: "url",
        required: true,
        description: "要抓取的网页地址",
        placeholder: "https://example.com",
      },
      {
        name: "selector",
        label: "CSS选择器",
        type: "string",
        description: "指定要提取的元素",
        placeholder: ".article-content",
      },
      {
        name: "extractType",
        label: "提取类型",
        type: "select",
        defaultValue: "text",
        options: [
          { label: "文本", value: "text" },
          { label: "HTML", value: "html" },
          { label: "Markdown", value: "markdown" },
        ],
        description: "内容提取格式",
      },
    ],
    outputs: [
      {
        name: "content",
        label: "网页内容",
        type: "text",
        description: "提取的网页内容",
      },
      {
        name: "metadata",
        label: "元数据",
        type: "object",
        description: "网页元数据（标题、描述等）",
      },
    ],
  },
  {
    id: "image-analyzer",
    type: "tool",
    label: "图像分析",
    iconName: "Image",
    category: "工具",
    description: "分析和理解图像内容",
    inputs: [
      {
        name: "imageUrl",
        label: "图像URL",
        type: "url",
        required: true,
        description: "图像文件的URL",
        placeholder: "https://example.com/image.jpg",
      },
      {
        name: "analysisType",
        label: "分析类型",
        type: "multiselect",
        defaultValue: ["describe"],
        options: [
          { label: "描述图像", value: "describe" },
          { label: "物体检测", value: "detect" },
          { label: "文字识别(OCR)", value: "ocr" },
          { label: "人脸识别", value: "face" },
        ],
        description: "选择分析类型",
      },
      {
        name: "detailLevel",
        label: "详细程度",
        type: "select",
        defaultValue: "medium",
        options: [
          { label: "简要", value: "low" },
          { label: "中等", value: "medium" },
          { label: "详细", value: "high" },
        ],
        description: "描述的详细程度",
      },
    ],
    outputs: [
      {
        name: "description",
        label: "图像描述",
        type: "text",
        description: "图像内容的文字描述",
      },
      {
        name: "objects",
        label: "检测到的物体",
        type: "array",
        description: "图像中的物体列表",
      },
      {
        name: "text",
        label: "识别的文字",
        type: "string",
        description: "OCR识别的文字内容",
      },
    ],
  },
  {
    id: "data-transformer",
    type: "tool",
    label: "数据转换",
    iconName: "Repeat",
    category: "工具",
    description: "转换和处理数据格式",
    inputs: [
      {
        name: "inputData",
        label: "输入数据",
        type: "any",
        required: true,
        description: "要转换的数据",
      },
      {
        name: "sourceFormat",
        label: "源格式",
        type: "select",
        defaultValue: "json",
        options: [
          { label: "JSON", value: "json" },
          { label: "XML", value: "xml" },
          { label: "CSV", value: "csv" },
          { label: "YAML", value: "yaml" },
        ],
        description: "数据源格式",
      },
      {
        name: "targetFormat",
        label: "目标格式",
        type: "select",
        defaultValue: "json",
        options: [
          { label: "JSON", value: "json" },
          { label: "XML", value: "xml" },
          { label: "CSV", value: "csv" },
          { label: "YAML", value: "yaml" },
        ],
        description: "转换后的格式",
      },
      {
        name: "transformRule",
        label: "转换规则",
        type: "text",
        description: "自定义转换规则（可选）",
      },
    ],
    outputs: [
      {
        name: "outputData",
        label: "输出数据",
        type: "any",
        description: "转换后的数据",
      },
      {
        name: "success",
        label: "转换成功",
        type: "boolean",
        description: "转换是否成功",
      },
    ],
  },
  {
    id: "email-tool",
    type: "tool",
    label: "邮件发送",
    iconName: "Mail",
    category: "工具",
    description: "发送电子邮件",
    inputs: [
      {
        name: "to",
        label: "收件人",
        type: "email",
        required: true,
        description: "收件人邮箱地址",
        placeholder: "user@example.com",
      },
      {
        name: "subject",
        label: "主题",
        type: "string",
        required: true,
        description: "邮件主题",
        placeholder: "邮件主题",
      },
      {
        name: "body",
        label: "邮件内容",
        type: "text",
        required: true,
        description: "邮件正文",
        placeholder: "邮件正文内容...",
      },
      {
        name: "cc",
        label: "抄送",
        type: "string",
        description: "抄送邮箱地址（多个用逗号分隔）",
      },
      {
        name: "attachments",
        label: "附件",
        type: "array",
        description: "附件文件列表",
      },
    ],
    outputs: [
      {
        name: "success",
        label: "发送成功",
        type: "boolean",
        description: "是否发送成功",
      },
      {
        name: "messageId",
        label: "消息ID",
        type: "string",
        description: "邮件的唯一标识",
      },
    ],
  },
  {
    id: "condition-router",
    type: "router",
    label: "条件路由",
    iconName: "GitBranch",
    category: "控制",
    description: "根据条件选择执行分支",
    inputs: [
      {
        name: "condition",
        label: "条件表达式",
        type: "string",
        required: true,
        description: "判断条件（支持JavaScript表达式）",
        placeholder: "value > 10",
      },
      {
        name: "value",
        label: "判断值",
        type: "any",
        description: "用于判断的值",
      },
    ],
    outputs: [
      {
        name: "result",
        label: "判断结果",
        type: "boolean",
        description: "条件是否满足",
      },
      {
        name: "branchTaken",
        label: "执行分支",
        type: "string",
        description: "选择的分支路径",
      },
    ],
  },
  {
    id: "loop-iterator",
    type: "control",
    label: "循环迭代",
    iconName: "Repeat",
    category: "控制",
    description: "遍历数组或对象",
    inputs: [
      {
        name: "items",
        label: "数据集合",
        type: "array",
        required: true,
        description: "要遍历的数组或对象",
      },
      {
        name: "maxIterations",
        label: "最大迭代次数",
        type: "number",
        defaultValue: 100,
        validation: { min: 1, max: 1000 },
        description: "最大循环次数限制",
      },
      {
        name: "breakCondition",
        label: "中断条件",
        type: "string",
        description: "提前中断循环的条件",
      },
    ],
    outputs: [
      {
        name: "currentItem",
        label: "当前项",
        type: "any",
        description: "当前迭代的项目",
      },
      {
        name: "index",
        label: "索引",
        type: "number",
        description: "当前迭代的索引",
      },
      {
        name: "results",
        label: "处理结果",
        type: "array",
        description: "所有迭代的结果集合",
      },
    ],
  },
  {
    id: "text-processor",
    type: "tool",
    label: "文本处理",
    iconName: "Type",
    category: "工具",
    description: "文本处理和转换",
    inputs: [
      {
        name: "text",
        label: "输入文本",
        type: "text",
        required: true,
        description: "要处理的文本",
      },
      {
        name: "operation",
        label: "操作类型",
        type: "select",
        defaultValue: "trim",
        options: [
          { label: "去除空格", value: "trim" },
          { label: "大写", value: "uppercase" },
          { label: "小写", value: "lowercase" },
          { label: "分割", value: "split" },
          { label: "替换", value: "replace" },
          { label: "提取", value: "extract" },
        ],
        description: "文本处理操作",
      },
      {
        name: "params",
        label: "操作参数",
        type: "object",
        description: "操作相关参数（如分隔符、正则等）",
      },
    ],
    outputs: [
      {
        name: "result",
        label: "处理结果",
        type: "any",
        description: "处理后的文本或数组",
      },
    ],
  },
]
